package com.rbcs.flow.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.systop.common.modules.dept.model.Dept;
import com.systop.common.modules.security.user.model.User;
import com.systop.core.Constants;
import com.systop.core.model.BaseModel;

/**
 * 流程节点
 * 
 * @author Nice
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "nodes")
public class Node extends BaseModel {

	private Integer id;

	// 标识哪一级部门审核
	private Dept dept;

	// 最终具体审核人
	private User auditor;

	private Date audDate;

	private String descn;

	// 状态[pass,nopass]
	private String status;

	private Flow flow;

	private Integer orderId;

	// 有权利审核的人userid1,userid2
	private String auditorIds;

	// 有权利审核的人userName1,userName2
	private String auditorNames;
	
	//是否财务
	private String isFinance = Constants.NO;

	@Id
	@GeneratedValue(generator = "hibseq")
	@GenericGenerator(name = "hibseq", strategy = "hilo")
	@Column(name = "id", nullable = false)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "dept_id")
	public Dept getDept() {
		return this.dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "auditor_id")
	public User getAuditor() {
		return auditor;
	}

	public void setAuditor(User auditor) {
		this.auditor = auditor;
	}

	public Date getAudDate() {
		return audDate;
	}

	public void setAudDate(Date audDate) {
		this.audDate = audDate;
	}

	public String getDescn() {
		return descn;
	}

	public void setDescn(String descn) {
		this.descn = descn;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "flow_id")
	public Flow getFlow() {
		return flow;
	}

	public void setFlow(Flow flow) {
		this.flow = flow;
	}

	public Integer getOrderId() {
		return orderId;
	}

	public void setOrderId(Integer orderId) {
		this.orderId = orderId;
	}

	public String getAuditorIds() {
		return auditorIds;
	}

	public void setAuditorIds(String auditorIds) {
		this.auditorIds = auditorIds;
	}

	public String getAuditorNames() {
		return auditorNames;
	}

	public void setAuditorNames(String auditorNames) {
		this.auditorNames = auditorNames;
	}
	
	@Column(name = "is_finance")
	public String getIsFinance() {
		return isFinance;
	}

	public void setIsFinance(String isFinance) {
		this.isFinance = isFinance;
	}

	/**
	 * 重新赋值，高亮显示审批人
	 * @param userName
	 */
	public void resetAuditorNames(String userName) {
		StringBuffer newUserName = new StringBuffer("<font color='blue'>");
		newUserName.append(userName).append("</font>");
		auditorNames = auditorNames.replace(userName, newUserName.toString());
	}

}
